/**
 * Created by Ren on 2015/6/3.
 */
function Bullet(ctx, x, y, buls, bulSpeed, director, img, bulletAudio, r, w, h)
{
    this.ctx = ctx;
    this.bulletAudio = bulletAudio;
    this.img = new Image();
    this.img.src= img;
    this.x = x + 21;
    this.y = y - 3;
    this.r = r;
    this.buls = buls;
    this.exploded = false;
    this.bulSpeed = bulSpeed;
    this.director = director;
    this.width = w;
    this.height = h;
}
Bullet.prototype.draw = function() {
    if(!this.exploded)
    {
        drawImage2(this.ctx, this.img, 0, 0, this.width, this.height, this.x, this.y, this.r, this.width/2, this.height/2);
        switch (this.director)
        {
            case 0:
                this.y -= this.bulSpeed;
                break;
            case 1:
                this.y += this.bulSpeed;
                break;
            case 2:
                this.x += this.bulSpeed;
                this.y += this.bulSpeed;
                break;
            case 3:
                this.x -= this.bulSpeed
                this.y += this.bulSpeed;
                break;
            case 4:
                this.x += this.bulSpeed;
                this.y -= this.bulSpeed
                break;
            case 5:
                this.x -= this.bulSpeed
                this.y -= this.bulSpeed;
                break;
            case 6:
                this.x -= this.bulSpeed;
                break;
            case 7:
                this.x += this.bulSpeed;
                break;
            case 8 :
                this.x += this.bulSpeed*Math.sin(Math.PI - this.r)
                this.y += this.bulSpeed;
                break;
            default :
                this.x += this.bulSpeed*Math.sin(this.r)
                this.y -= this.bulSpeed;
                break;
        }
    }
    else
    {
        this.bulletAudio.currentTime = 0;
        this.bulletAudio.pause();
        this.bulletAudio.play();
        this.isMusic = false;
        this.buls.remove(this);
    }
}
Bullet.prototype.getCenter=function() {
    return new Point(this.x + this.width/2, this.y + this.height/2);
}